function finalStats = hunterStats()%(equipASPD, maxLvl)
	%temporales
	more off;
	clear;
	clc;
	tic()
	global status;
	status = "-";
	equipASPD = 60;
	maxLvl = 99;
	global GLORIA;
	GLORIA = 30;
	
	SteelCrowSkillLvl= 10;
	bestDmgPerSecond = 0;
	bestBBDmg = 0;
	finalStats = [1, 1, 1, 1];
	bestHitsPerSecond = 0;
	bestDmgPerSecond = 0;
	bestAspd = 0;
	
	counter = 33;
	looper = 1;
	
	agi = 80
	while (agi <=99)
		dex = 25
		while (dex <= 99)
			luk = 59
			while (luk <= 99)
				int = 70
				while (int <=99)
					currentAspd = aspdCalculator(agi, dex, equipASPD);
					currentHitsPerSecond = hitsPerSecond(currentAspd);
					currentBBDmg = BBDmg(int, dex, SteelCrowSkillLvl);
					currentDmgPerSecond = currentHitsPerSecond  * currentBBDmg * ((GLORIA + luk) * 0.003)*(1-((GLORIA + luk)*0.003));
					if(looper == 1)
						clc();
						showProgress();%para mostrar progreso
						printStatus(agi, dex, luk, int, finalStats, currentBBDmg, currentHitsPerSecond, currentDmgPerSecond, currentAspd, bestBBDmg, bestHitsPerSecond, bestDmgPerSecond, bestAspd);
						looper = counter;
					else
						looper -= 1;
					endif
					if(correctStats(agi, dex, luk, int, maxLvl) && not(bestDmgPerSecond > currentDmgPerSecond ));
						bestAspd = currentAspd;
						bestBBDmg = currentBBDmg;
						bestHitsPerSecond = currentHitsPerSecond;
						bestDmgPerSecond = currentDmgPerSecond;
						finalStats = [agi, dex, luk, int];
					endif
					if(not(correctStats(agi, dex, luk, int, maxLvl) ))
						int = 99;
					else
						int+=1;
					endif
				endwhile
				luk+=1;
			endwhile
			dex+=1;
		endwhile
		agi+=1;
	endwhile
	
	totalTime = toc();
	printf("\n\n**Se calculo en %g segundos**\n\n", totalTime);
endfunction

function result = correctStats(agi, dex, luk, int, maxLvl)
	a_cost = 0;
	d_cost = 0;
	i_cost = 0;
	l_cost = 0;
	maxStats = 48;
	result = 0;
	
	for s = 1:(maxLvl-1)
		maxStats += floor(s/5)+3;
	endfor
	
	for a = 2:agi
		a_cost += floor((a-1) / 10) + 2 ;
	endfor
	
	for d = 2:dex
		d_cost += floor((d-1) / 10) + 2;
	endfor
	
	if (maxStats > a_cost + d_cost)
		for l = 2:luk
			l_cost += floor((l-1) / 10) + 2;
		endfor
		if(maxStats > a_cost + d_cost + l_cost)
			for i = 2:int
				i_cost += floor((i-1) / 10) + 2;
			endfor
			result = (maxStats > a_cost + d_cost + l_cost  + i_cost);
		endif
	endif
endfunction

function [] = printStatus(agi, dex, luk, int, finalStats, currentBBDmg, currentHitsPerSecond, currentDmgPerSecond, currentAspd, bestBBDmg, bestHitsPerSecond, bestDmgPerSecond, bestAspd)
	global GLORIA;
	printf("\n\n==================================\n")
	printf("\nCurrent Stats:\n ");
	printf(" Agi: %g\n  Dex: %g\n  Luk: %g\n  Int: %g\n", agi, dex, luk, int)
	printf("\nSubStats:\n");
	printf("   Dmg/s: %g\n", currentDmgPerSecond);
	printf("   Crit : %g\n", (GLORIA+luk) * 0.3);
	printf("   Hits/s: %g\n", currentHitsPerSecond);
	printf("   Blitz Beat Dmg: %g\n", currentBBDmg);	
	printf("   Aspd: %g\n", currentAspd);	
	printf("\n==================================\n")
	printf("\nBest Stats:\n");
	printf("  Agi: %g\n  Dex: %g\n  Luk: %g\n  Int: %g\n", finalStats)
	printf("\nSubStats:\n");
	printf("   Dmg/s: %g\n", bestDmgPerSecond);
	printf("   Crit : %g\n",  (GLORIA + finalStats(3)) * 0.3);
	printf("   Hits/s: %g\n", bestHitsPerSecond);
	printf("   Blitz Beat Dmg: %g\n", bestBBDmg);
	printf("   Aspd: %g\n", bestAspd);
	printf("\n==================================\n")
endfunction

function [] = showProgress()
	global status;
	if(strcmp(status, "-"))
		status = "\\";
	elseif(strcmp(status, "\\"))
		status = "l";
	elseif(strcmp(status, "l"))
		status = "/";
	elseif(strcmp(status, "/"))
		status = "-";
	endif
	printf("\n %s \n", status);
endfunction











